<!DOCTYPE html>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="contextPath" value="${pageContext.request.contextPath}" />
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>工作组工资详细页面</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<meta content="width=device-width, initial-scale=1" name="viewport">
<link rel="stylesheet" type="text/css" href="${contextPath}/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="${contextPath}/css/bootstrap-theme.min.css" />
<link rel="stylesheet" type="text/css" href="${contextPath}/css/public.css">
<link href="${contextPath}/css/jquery-ui.min.css" rel="stylesheet">
<link href="${contextPath}/css/jquery-ui.theme.min.css" rel="stylesheet">
<style type="text/css">
	.input-group-addon,.form-control{padding:6px;}
	.ui-datepicker .ui-datepicker-title select{color:#1c94c4}
	.form-btn1{height: 50px;float: left;}
</style>
<script type="text/javascript" src="${contextPath}/js/jquery.min.js"></script>
<script type="text/javascript" src="${contextPath}/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${contextPath}/js/common.js"></script>
<script type="text/javascript" src="${contextPath}/js/jquery.ui.core.js"></script>
<script type="text/javascript" src="${contextPath}/js/jquery.ui.widget.js"></script>
<script type="text/javascript" src="${contextPath}/js/jquery.ui.datepicker.js"></script>
<script type="text/javascript" src="${contextPath}/js/jquery.ui.datepicker-ch.js"></script>
</head>
<body>
	<div class="container" style="max-width: 1366px">
		<div class="panel panel-default" id="workerSalarList">
			<div class="panel-heading">${model.workGroupName}的工作者工资信息</div>
			<div class="panel-body">
				<form class="form-inline" role="form">
					<div class="col-sm-3" style="width: 175px;">
						<div class="form-group">
							<div class="input-group" style="width: 170px;">
								<div class="input-group-addon">用户名</div>
								<input class="form-control"
									onkeydown="if(event.keyCode==13){return false;}"
									id="userNameCondition1" type="text" placeholder="查询用户">
							</div>
						</div>
					</div>
					<div class="col-sm-3" style="width: 101px;">
						<div class="form-group">
							<div class="input-group" style="width: 96px;">
								<div class="input-group-addon">金额</div>
								<input class="form-control"
									onkeydown="if(event.keyCode==13){return false;}"
									id="salaryLine" type="text" placeholder="输入金额" value="0">
							</div>
						</div>
					</div>
					<div class="col-xs-2" style="width: 111px;">
						<div class="form-group">
							<div class="input-group" style="width: 105px;">
								<div class="input-group-addon">结算</div>
								<select class="form-control" id="payOffType" style="width: 70px;">
									<option value="2">全部</option>
									<option value="1">已结</option>
									<option value="0">未结</option>
								</select>
							</div>
						</div>
					</div>
					<div class="btn2" style="float: right;">
						<button type="button" id="searchSalaryBtn" class="btn btn-default">查询</button>
						<button type="button" id="payOffBtn" class="btn btn-default">结算</button>
					</div>
				</form>
				<div style="clear: both;"></div>
			</div>
			<table class="table table-striped table-bordered">
				<thead>
					<tr>
						<th width='4%'>序号</th>
						<th width='12%'>姓名</th>
						<th width='12%'>银行卡号</th>
						<th width='15%'>标注时间(小时)</th>
						<th width='6%'>一层金额</th>
						<th width='6%'>三层金额</th>
						<th width='5%'>总金额</th>
						<th width='10%' id="oneLayerSubsidyTH">一层补贴(%)</th>
						<th width='10%' title="工作者第一次回传任务后到审核完成没有被更改过的任务为正确">准确率</th>
						<th width='5%'><a href="#" id="choose"><span
								id="choose-p">全选</span>
						</a>
						</th>
						<th width='12%'>支付宝信息</th>
					</tr>
				</thead>
				<tbody id="workerSalary-tbody"></tbody>
			</table>
			<ul class="pagination"></ul>
		</div>

	</div>
	<script type="text/javascript">
		var userNameCondition1 = "";	
		var dateType1 = ${model.dateType };
		var beginDate1 = "${model.beginDate }";
		var endDate1 = "${model.endDate }";
		var salaryLine = 0;
		var payOffType = 2;//2:常规 0:未结 1:已结
		var workGroupCode = "${model.workGroupCode }";
		
		$(document).ready(function(){
			
			//结算按钮
			$("#payOffBtn").attr("disabled","disabled");
			workerSalaryList(1);
			/*--------------------------------------点击查询按钮-------------------------------------------------------*/
			$("#searchSalaryBtn").click(function(){
				salaryLine = $("#salaryLine").val();
				payOffType = $("#payOffType").val();
				if(salaryLine.length == 0){
					salaryLine = 0;
				}
				userNameCondition1 = $("#userNameCondition1").val();
				//
				var noPay = $("#payOffType").val();
				if(noPay == 0){
					$("#payOffBtn").removeAttr("disabled");
				}else{
					$("#payOffBtn").attr("disabled","disabled");
				}	
				workerSalaryList(1);
			});
		});
		
		/*----------------------------------------------用户薪金页----------------------------------------------------------------*/
		workerSalaryList = function(pageNum){
			$.ajax({
				type:'POST',
				data:{"page":pageNum,"userNameCondition":userNameCondition1,"dateType":dateType1,"beginDate":beginDate1,"endDate":endDate1,"salaryLine":salaryLine,"payOffType":payOffType,"workGroupCode":workGroupCode},
				url:'${contextPath}/security/workerSalary',
				dataType:'json',
				success:function(data){
					$("#workerSalary-tbody").empty();			
					if(data.list == ""){
						$("#workerSalary-tbody").empty();
						$("#workerSalarList .pageGoBtn").empty();
						$("#workerSalary-tbody").append("<tr class='text-danger'><td colspan='8'>无内容</td></tr>");
					}else{
						pageTotal = data.totlePage; 
						var oneLayerSubsidyPercent = 0;
						$.each(data.list,function(i,item){
							if(i==0){
								oneLayerSubsidyPercent = item.oneLayerSubsidyPercent*100;
							}
							var oneLayerSubsidy;//一层补助
							var oneLayerSalary; //一层任务工资
							if(item.oneLayerSalary!=undefined){
								oneLayerSalary = (item.oneLayerSalary*1).toFixed(2);
								if(item.taskMarkTimeMonth>5){//计算一层任务补助有效时间大于5小时才开始计算
									oneLayerSubsidy = (oneLayerSalary*item.oneLayerSubsidyPercent).toFixed(2);
								}else{
									oneLayerSubsidy = "-";
								}
							}else{
								oneLayerSalary = "-";
								oneLayerSubsidy = "-"
							}
							var threeLayerSalary;//三层任务工资
							if(item.threeLayerSalary!=undefined){
								threeLayerSalary = (item.threeLayerSalary*1).toFixed(2);
							}else{
								threeLayerSalary = "-";
							}
							
							$("#workerSalary-tbody").append(
							"<tr>"+
								"<td>"+(i + 1)+"</td>"+
								"<td>"+item.realName+"</td>"+
								"<td>"+item.bankCard+"</td>"+
								"<td title='约"+item.sec+"秒'>"+item.taskMarkTimeMonth  +"</td>"+
								"<td>"+oneLayerSalary+"</td>"+
								"<td>"+threeLayerSalary+"</td>"+
								"<td id = salary"+ item.workerId +">"+item.salary+"</td>"+
								"<td>"+oneLayerSubsidy+"</td>"+
								"<td title = '总下载任务数: "+item.downAllNum+", 未上传任务数: "+item.notUploadNum+", 未审核数: "+item.notSettlementNum+
								", 放弃数: "+item.giveUpNum+", 超时数: "+item.overTimeNum+", 被系统收回数: "+item.systemTakeBackNum+
								", 错误数: "+item.modifyNum+", 正确数: "+item.oneTimeSuccessNum+"'><span>"+item.oneTimeSuccessRate+"</span></td>"+
								"<td><input type='checkbox' class='checkbox1' name='checkbox1' value='"+item.workerId+"'/></td>"+  //beginDate1+" "+endDate1+" "+dateType1
								"<td><a target='_blank' href='${contextPath}/security/queryAlipayInfos?workerId="+item.workerId+"&beginDate="+beginDate1+"&endDate="+endDate1+"&dateType="+dateType1+"&realName="+item.realName+"'>点击查看</a></td>"+
							"</tr>"
							);
							getSalary(item.workerId,item.salary);			
						});
						$("#oneLayerSubsidyTH").html("一层补贴("+oneLayerSubsidyPercent+"%)");
//						getSumSalary(userNameCondition1,dateType1,beginDate1,endDate1,salaryLine,payOffType);
						
						var pageDom = $("#workerSalarList .pagination");
							pageDom.empty();
							page.creatPageHTML(pageNum,pageTotal,pageDom,"workerSalaryList");
							/*--------------------------------------跳转页-------------------------------------------------------*/
							$("#workerSalarList .pageGoBtn").click(function(){
								var pageNum = 0;
								pageNum = $("#workerSalarList .pageGoText").val();
								if(pageNum !=0&&0<pageNum&&pageNum<pageTotal+1){
									workerSalaryList(pageNum);
								}
							});					
					}
				}
			});
		};
		/*-----------------------------------------------获得薪金---------------------------------------------------------------*/
		getSalary = function(workerId,salary){
			$.ajax({
				type:'POST',
				data:{"workerId":workerId},
				url:'${contextPath}/security/salaryByWorkerId',
				dataType:'json',
				success:function(data){
					$("salary"+workerId).text(data);
				}
			});
		};
	
		/*--------------------------------------全选-----------------------------------------------------------------*/
		$("#choose").click(function(){
			var choose = $("#choose-p").text();
			if(choose == "全选"){
				$(".checkbox1").prop("checked",true);
				$("#choose-p").text("取消");
			}else{
				$(".checkbox1").prop("checked",false);
				$("#choose-p").text("全选");
			}
		});
		/*---------------------------------------结算---------------------------------------------------------------*/
		$("#payOffBtn").click(function(){
			payOffType = $("#payOffType").val();
			if(payOffType == 0){
				var conWin = confirm("确定要执行结算吗？");
				if(conWin){
					var checkList = $(".checkbox1");
					var l = checkList.length;
					var str="";
					for(var i=0;i<l;i++){
						if (checkList[i].checked == true) {
							var workerId = checkList[i].value;
							str = workerId +"/"+str;
		        		}
					}			
					payOff(str);	
				}
			}else{
				alert("现在显示的不是未结数据,不能进行结算!!");
			}	
		});
		/*--------------------------------------结算工资-------------------------------------------*/
		payOff = function(str){
			alert(str+"__"+dateType1+"__"+beginDate1+"__"+endDate1);
			$.ajax({
				type:'POST',
				data:{"workerIds":str,"dateType":dateType1,"beginDate":beginDate1,"endDate":endDate1},
				url:'${contextPath}/security/payOff',
				dataType:'json',
				success:function(data){
					var replay = data.replay;
					if(replay>0){
						alert("结算工资完成!");
					}else{
						alert("结算工资出错!");
					}
					workerSalaryList(1);	
				}	
			});
		};
		/*--------------------------------------获得语音标注总和-------------------------------------------*/
		getMarkTimeTotle = function(userNameCondition,taskUpload,dateType,beginDate,endDate){
			$.ajax({
				type:'POST',
				data:{"userNameCondition":userNameCondition,"taskUpload":taskUpload,"dateType":dateType,"beginDate":beginDate,"endDate":endDate},
				url:'${contextPath}/security/getMarkTimeTotle',
				dataType:'json',
				success:function(data){
					var taskMarkTimeMonthTotle = data.taskMarkTimeMonthTotle;
					var aduitingMarkTimeMonthTotle = data.aduitingMarkTimeMonthTotle;			
					$("#aduitingMarkTimeMonthTotle").text("待审标注："+aduitingMarkTimeMonthTotle);
					$("#taskMarkTimeMonthTotle").text("有效标注："+taskMarkTimeMonthTotle);
				}
			});
		};
//		getSumSalary = function(userNameCondition,dateType,beginDate,endDate,salaryLine,payOffType){
//			$.ajax({
//				type:'POST',
//				data:{"userNameCondition":userNameCondition,"dateType":dateType,"beginDate":beginDate,"endDate":endDate,"salaryLine":salaryLine,"payOffType":payOffType},
//				url:'${contextPath}/security/getSumSalary',
//				dataType:'json',
//				success:function(data){
//					var sumSalary = data.sumSalary;			
//					$("#taskMarkTimeMonthTotle1").text("有效标注："+(sumSalary/3600).toFixed(2)+" 小时");
//					$("#aduitingMarkTimeMonthTotle1").text("总金额："+(sumSalary*data.salary/3600).toFixed(2)+" 元");
//				}
//			});
//		};
		/*
		数据显示顺序
		downCount+"/"+unUploadCount+"/"+waitingCount
		finishCount+"/"+giveUpCount+"/"+oldCount
		*/
		getMarkTime = function(userId,i,nowUserType,pageNum,userNameCondition,taskUpload,dateType,beginDate,endDate){
			$.ajax({
				type:'POST',
				data:{"userId":userId,"userType":nowUserType,"page":pageNum,"userNameCondition":userNameCondition,"taskUpload":taskUpload,"dateType":dateType,"beginDate":beginDate,"endDate":endDate},
				url:'${contextPath}/security/getMarkTime',
				dataType:'json',
				success:function(data){
					$("#markTime"+i).text(data.markTime);
					$("#waitingMarkTime"+i).text(data.waitMarkTime);
					$("#downCount"+i).text(data.downCount+"/"+data.unUpLoadCount+"/"+data.waitingEffectiveCount);
					$("#finishCount"+i).text(data.finishCount+"/"+data.giveUpCount+"/"+data.oldCount);
					$("#referralNum"+i).html("<a target='_blank' href='${contextPath}/security/getViewOfReferrals?userId="+userId+"'>"+data.referralNum+"</a>");  //显示推荐过的人数
				}
			});
		};

	</script>
</body>
</html>
